<?php

namespace app\common\model;

use think\Model;


class NewsTag extends Model
{





    // 表名
    protected $name = 'news_tag';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'flag_text'
    ];

    public function category()
    {
        return $this->belongsTo('\app\common\model\Category', 'category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function getFlagList()
    {
        return ['0' => __('Flag 0'), '1' => __('Flag 1')];
    }


    public function getFlagTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['flag']) ? $data['flag'] : '');
        $list = $this->getFlagList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
